package com.zhao.kafka.redis

import com.zhao.kafka.mysql.ConfigConstants
import redis.clients.jedis.{JedisPool, JedisPoolConfig}

/**
 * Description: Redis连接类<br/>
 * Copyright (c) ，2020 ， 赵 <br/>
 * This program is protected by copyright laws. <br/>
 * Date： 2020/12/25 14:08
 *
 * @author 柒柒
 * @version : 1.0
 */

object JedisConnPool {

  val config: JedisPoolConfig = new JedisPoolConfig
  //最大连接数
  config.setMaxTotal(60)
  //最大空闲连接数
  config.setMaxIdle(10)
  config.setTestOnBorrow(true)

  //服务器IP
  val redisAddress: String = ConfigConstants.redisAddress.toString
  //端口号
  val redisPort: Int = ConfigConstants.redisPort.toInt
  //访问密码
  val redisAuth: String = ConfigConstants.redisAuth
  //等待可用连接的最大空间
  val redisTimeout: Int = ConfigConstants.redisTimeout.toInt

  val pool: JedisPool = new JedisPool(config, redisAddress, redisPort, redisTimeout, redisAuth)

  def getConnection() = {
    pool.getResource
  }
}
